//
//  CellOfNews.m
//  objc_property_t 的使用
//
//  Created by dllo on 16/7/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellOfNews.h"
#import "UIColor+WLZ_HexRGB.h"
#import "Masonry.h"

@interface CellOfNews ()

@property (nonnull, nonatomic, strong) UIImageView *newsImageView;
@property (nonnull, nonatomic, strong) UILabel *titleLabel;
@property (nonnull, nonatomic, strong) UILabel *summaryLabel;
@property (nonnull, nonatomic, strong) UILabel *commentCountLabel;
@property (nonnull, nonatomic, strong) UILabel *updateTimeLabel;



@end

@implementation CellOfNews

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor colorFromHexRGB:@"0xfffff1"];
        [self createSubviews];
    }
    return self;
}

/** 创建视图 */
- (void)createSubviews
{
    _newsImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.png"]];
    [self.contentView addSubview:_newsImageView];
    
    _titleLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_titleLabel];
    _titleLabel.font = [UIFont systemFontOfSize:17];
    
    _summaryLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_summaryLabel];
    _summaryLabel.font = [UIFont systemFontOfSize:15];
    _summaryLabel.numberOfLines = 4;
    _summaryLabel.textColor = [UIColor colorFromHexRGB:@"666666"];
    
    _commentCountLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_commentCountLabel];
    _commentCountLabel.font = [UIFont systemFontOfSize:13];
    _commentCountLabel.textAlignment = NSTextAlignmentRight;
    
    _updateTimeLabel = [[UILabel alloc]init];
    [self.contentView addSubview:_updateTimeLabel];
    _updateTimeLabel.font = [UIFont systemFontOfSize:13];
    _updateTimeLabel.textAlignment = NSTextAlignmentRight;
    
    
    
    }

- (void)setModel:(NewsModel *)model
{
    _model = model;
    _titleLabel.text = model.title;
    _summaryLabel.text = model.summary;
    _commentCountLabel.text= [NSString stringWithFormat:@"评论：%ld", model.commentCount];
    _updateTimeLabel.text = model.lastUpdateTime;
}

/** 布局子视图 */
- (void)layoutSubviews
{
    
    [_newsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).with.offset(40);
        make.left.mas_equalTo(self.contentView).with.offset(10);
        make.bottom.mas_equalTo(self.contentView).with.offset(-15);
        make.width.mas_greaterThanOrEqualTo(@89);
        make.width.mas_lessThanOrEqualTo(@90);


    }];
    
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).with.offset(15);
        make.left.mas_equalTo(self.contentView).with.offset(10);
        make.right.mas_equalTo(self.contentView).with.offset(-10);
        make.bottom.mas_equalTo(self.newsImageView.mas_top).with.offset(-5);
    }];

    
    
    [_commentCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView).with.offset(-10);
        make.left.mas_equalTo(self.newsImageView.mas_right).with.offset(30);
        make.width.mas_greaterThanOrEqualTo(50);
        make.height.mas_greaterThanOrEqualTo(@13);
    }];
    
    [_updateTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView).with.offset(-10);
        make.left.mas_equalTo(self.commentCountLabel.mas_right).with.offset(5);
        make.right.mas_equalTo(self.contentView).with.offset(-10);
        make.width.mas_greaterThanOrEqualTo(@50);
        make.height.mas_greaterThanOrEqualTo(@13);
    }];

    [_summaryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.newsImageView);
        make.left.mas_equalTo(_newsImageView.mas_right).with.offset(10);
        make.right.mas_equalTo(self.contentView).with.offset(-10);
        make.bottom.mas_equalTo(self.contentView).with.offset(-35);
    }];
}



@end
